<?php
namespace app\admin\validate;

use think\Validate;
use think\Db;
class STValidate extends Validate
{
	protected $rule = [
        ['name', 'require|chs', '姓名不能为空|姓名只能填写汉字'],
        ['phone', 'require|is_phone', '手机号不能为空|手机号格式不正确'],
        ['nation', 'chs|require', '民族只能填写汉字|民族不能为空'],
        ['school_id', 'school', '请选择学校/该学校不存在'],
		['id_card', 'id_card|require', '身份证号格式不正确|身份证号不能为空'],
    ];

    protected function is_phone($value){
		if(preg_match("/^1[34578]\d{9}$/", $value)){
			return true;
		}else{
			return false;
		}
	}
	protected function school($value){
		if(DB::name('school_specialty')->where('id',$value)->find()){
			return true;
		}else{
			return false;
		}
	}
	protected function id_card($value){
		if(preg_match("/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/", $value)){
			return true;
		}else{
			return false;
		}
	}
}
